
#import "NSString+Extension.h"
#import "KRConst.h"

@implementation NSString (Extension)
- (CGSize)sizeWithFont:(UIFont *)font maxW:(CGFloat)maxW
{
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = font;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    
    // 获得系统版本
    if (iOS7) { // iOS7以上
        return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    } else { // iOS7以下
        return [self sizeWithFont:font constrainedToSize:maxSize];
    }
}

- (CGSize)sizeWithFont:(UIFont *)font
{
    return [self sizeWithFont:font maxW:MAXFLOAT];
}

- (BOOL)containsPartString:(NSString *)part
{
    if (iOS8) { // iOS8以上
        if ([self containsString:part]) return YES;
    } else if (iOS7){ // iOS8以下
        if ([self rangeOfString:part].length) return YES;
    }
    return NO;
}



@end
